package top.lyc829.note;


import java.util.Arrays;
import java.util.Comparator;

interface Compare<T> {
    int compare(T first, T second);
}

public class LengthComparator implements Comparator<String> {
    @Override
    public int compare(String first, String second) {
        return first.length() - second.length();
    }

    public static void main(String[] args) {
        LengthComparator lengthComparator = new LengthComparator();
        String[] fruits = {"peter", "paul", "Mary"};
        Arrays.sort(fruits, new LengthComparator());

        System.out.println(Arrays.toString(fruits));
    }
}


